﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

using log4net;
using Common;
using CashFlow.Db.Entity;
using SysAdmin._01_Config;
using SysAdmin._03_Service._00_Db;
using SysAdmin._04_Form._00_Common;

namespace SysAdmin._04_Form._02_User
{
    public partial class UserAccountInfoForm : Form
    {
        private static ILog _logger = LogManager.GetLogger(typeof(UserAccountInfoForm));

        public int UserId { get; set; }
        private UserAccountInfoEntity UserAccountInfo { get; set; }

        public UserAccountInfoForm()
        {
            InitializeComponent();
        }

        private void ViewUserAccountInfoForm_Load(object sender, EventArgs e)
        {
            label2.Text = "";
            label3.Text = "";
            label5.Text = "";
        }

        private void ViewUserAccountInfoForm_Shown(object sender, EventArgs e)
        {
            try
            {
                UserAccountInfo = UserAccountInfoService.QueryByUserId(UserId);
                if (UserAccountInfo != null)
                {
                    if (!string.IsNullOrEmpty(UserAccountInfo.WechatCodePath))
                    {
                        string url = string.Format("{0}{1}", MyConfig.RemoteHostAddr, UserAccountInfo.WechatCodePath);
                        pictureBox1.Load(url);
                    }
                    if (!string.IsNullOrEmpty(UserAccountInfo.AlipayCodePath))
                    {
                        string url = string.Format("{0}{1}", MyConfig.RemoteHostAddr, UserAccountInfo.AlipayCodePath);
                        pictureBox2.Load(url);
                    }

                    label2.Text = UserAccountInfo.Bank;
                    label3.Text = UserAccountInfo.BankCardNo;
                    label5.Text = UserAccountInfo.BankAccountName;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                UICommonTool.ShowAlertDialog("网络错误！");
            }
        }

        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem.Text == "复制")
            {
                UICommonTool.SetClipboardText(label2.Text);
            }
        }

        private void contextMenuStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem.Text == "复制")
            {
                UICommonTool.SetClipboardText(label3.Text);
            }
        }

        private void contextMenuStrip3_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem.Text == "复制")
            {
                UICommonTool.SetClipboardText(label5.Text);
            }
        }
    }
}
